﻿
// MFCApplication2View.cpp: CMFCApplication2View 类的实现
//

#include "pch.h"
#include "framework.h"
// SHARED_HANDLERS 可以在实现预览、缩略图和搜索筛选器句柄的
// ATL 项目中进行定义，并允许与该项目共享文档代码。
#ifndef SHARED_HANDLERS
#include "MFCApplication2.h"
#endif

#include "MFCApplication2Doc.h"
#include "MFCApplication2View.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// CMFCApplication2View

IMPLEMENT_DYNCREATE(CMFCApplication2View, CScrollView)

BEGIN_MESSAGE_MAP(CMFCApplication2View, CScrollView)
	// 标准打印命令
	ON_COMMAND(ID_FILE_PRINT, &CScrollView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, &CScrollView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, &CScrollView::OnFilePrintPreview)
	ON_WM_MOUSEMOVE()
ON_COMMAND(ID_MENU_ORIGINAL, &CMFCApplication2View::OnMenuOriginal)
ON_COMMAND(ID_MENU_ONEINFOUR, &CMFCApplication2View::OnMenuOneinfour)
ON_COMMAND(ID_MENU_FOUR, &CMFCApplication2View::OnMenuFour)
END_MESSAGE_MAP()

// CMFCApplication2View 构造/析构

CMFCApplication2View::CMFCApplication2View() noexcept
{
	// TODO: 在此处添加构造代码

}

CMFCApplication2View::~CMFCApplication2View()
{
}

BOOL CMFCApplication2View::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: 在此处通过修改
	//  CREATESTRUCT cs 来修改窗口类或样式

	return CScrollView::PreCreateWindow(cs);
}

// CMFCApplication2View 绘图

void CMFCApplication2View::OnDraw(CDC* pDC)
{
	CMFCApplication2Doc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	if (!pDoc)
		return;
	//位图
	CBitmap bm;
	bm.LoadBitmapW(IDB_BITMAP1);
	CDC memDC;
	memDC.CreateCompatibleDC(pDC);
	memDC.SelectObject(&bm);
	BITMAP info; 
	bm.GetBitmap(&info);
	//根据选择来确定图片尺寸，画刷填充图片
	if (pDoc->m_select == 1)
		pDC->StretchBlt(0, 0, 400 , 300, &memDC,0, 0, info.bmWidth, info.bmHeight, SRCCOPY);
	if (pDoc->m_select == 2)
		pDC->StretchBlt(0, 0, 800 , 600 , &memDC, 0, 0, info.bmWidth, info.bmHeight, SRCCOPY);
	if(pDoc->m_select == 3)
		pDC->StretchBlt(0, 0, 200,  150 , &memDC, 0, 0, info.bmWidth,info.bmHeight, SRCCOPY);
	bm.DeleteObject();

	// TODO: 在此处为本机数据添加绘制代码
}

void CMFCApplication2View::OnInitialUpdate()
{
	CScrollView::OnInitialUpdate();

	CSize sizeTotal;
	// TODO: 计算此视图的合计大小
	sizeTotal.cx = 1000;
	sizeTotal.cy = 800;
	SetScrollSizes(MM_TEXT, sizeTotal);
}


// CMFCApplication2View 打印

BOOL CMFCApplication2View::OnPreparePrinting(CPrintInfo* pInfo)
{
	// 默认准备
	return DoPreparePrinting(pInfo);
}

void CMFCApplication2View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: 添加额外的打印前进行的初始化过程
}

void CMFCApplication2View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: 添加打印后进行的清理过程
}


// CMFCApplication2View 诊断

#ifdef _DEBUG
void CMFCApplication2View::AssertValid() const
{
	CScrollView::AssertValid();
}

void CMFCApplication2View::Dump(CDumpContext& dc) const
{
	CScrollView::Dump(dc);
}

CMFCApplication2Doc* CMFCApplication2View::GetDocument() const // 非调试版本是内联的
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMFCApplication2Doc)));
	return (CMFCApplication2Doc*)m_pDocument;
}
#endif //_DEBUG


// CMFCApplication2View 消息处理程序


void CMFCApplication2View::OnMouseMove(UINT nFlags, CPoint point)
{
	//鼠标移动消息的槽函数
	CDC* pDC = GetDC();
	CString str;
	//显示鼠标位置，及提示信息
	str.Format(L"Mouse[%d,%d], Ctrl+Q(*1)/W(*4)/E(*1/4)  ", point.x, point.y);
	//获取父窗口状态条，设置状态
	GetParent()->GetDescendantWindow(AFX_IDW_STATUS_BAR)->SetWindowText(str);

	CScrollView::OnMouseMove(nFlags, point);
}


void CMFCApplication2View::OnMenuOriginal()
{
	CMFCApplication2Doc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	if (!pDoc)
		return;
	pDoc->m_select = 1;
	//刷新视图区
	Invalidate();
	CString str;
	str.Format(L"当前选择:原图");
	//获得状态栏的指针
	CStatusBar* pStatusBar = (CStatusBar*)GetParentFrame()->GetDescendantWindow(ID_VIEW_STATUS_BAR);
	//在状态栏的第二个窗格中输出当前状态
	pStatusBar->SetPaneText(1, str); 

}


void CMFCApplication2View::OnMenuOneinfour()
{
	CMFCApplication2Doc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	if (!pDoc)
		return;
	pDoc->m_select = 3;
	//刷新视图区
	Invalidate();
	CString str;
	str.Format(L"当前选择:1/4");
	//获得状态栏的指针
	CStatusBar* pStatusBar = (CStatusBar*)GetParentFrame()->GetDescendantWindow(ID_VIEW_STATUS_BAR);
	//在状态栏的第二个窗格中输出当前状态
	pStatusBar->SetPaneText(1, str);
}


void CMFCApplication2View::OnMenuFour()
{
	CMFCApplication2Doc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	if (!pDoc)
		return;
	pDoc->m_select = 2;
	//刷新视图区
	Invalidate();
	CString str;
	str.Format(L"当前选择:4倍");
	//获得状态栏的指针
	CStatusBar* pStatusBar = (CStatusBar*)GetParentFrame()->GetDescendantWindow(ID_VIEW_STATUS_BAR);
	//在状态栏的第二个窗格中输出当前状态
	pStatusBar->SetPaneText(1, str);
}
